#include <stdio.h>
#include "Utils.h"
#include "LeNet.h"

//Test accurate rate is 0.320700 in both float and double
//Then i creat some testbench to figure out why,finally i find maxpooling is error,when get max ,i use o as init
//Now Test accurate is 0.320700 ????
//may accurate is loss when json convert
//yes! 0.000025 ->0.000010
//emmmm accurate is still 0.320700
//maybe the image transform has some error?
//normalize is to let value between [-1,1] but i did [-0.5,0.5]
//well now Test accurate rate is 0.445900 still lower than 0.6783
//now Test accurate rate is 0.451400
//cv imread formate is bgr rather than rgb
//now Test accurate rate is 0.672600 is almost equal 0.6783 in pytorch 

using namespace std;

#define skip 10

int main()
{
	//LeNet module("..\\refer\\LeNetFP32.json");
	LeNet module("..\\refer\\value_QTA.json");
	vector<string> files = getFilesList("..\\test");
	int total = files.size();
	int accurate = 0;
	int k = 0;
	for (int i = 0; i < total; i++)
	{
		k++;
		if (k < skip)  continue;
		k = 0;

		string filepath = files[i];
		int accurateIndex = filepath[filepath.find_last_of('_') - 1] - '0';
		Image image(filepath);
		int index = module.GetResultIndex(image);
		if (index == accurateIndex)
			accurate++;
		//printf("index:%d,%s\r\n", i, index == accurateIndex ? "success" : "fail");
	}
	printf("Test accurate rate is %f", (accurate / (float)total) * skip);
	return 0;
}

